<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script !src="">
    //数组是简单数字或者字符串的交集、并集、补集、差集  es6
    let arr1=[1,2,3,4,5],arr2=[4,5,6,7,8];
    let set1=new Set(arr1),set2=new Set(arr2);
    //交集
    let intersection=arr1.filter(item=>set2.has(item));
    console.log("交集",intersection);
    //并集
    let union=Array.from(new Set([...arr1,...arr2]));;
    console.log("并集", union);
    //补集 两个数组各自没有的集合
    let complement=[...arr1.filter(item=>set2.has(item)==false),...arr2.filter(item=>set1.has(item)==false)];
    console.log("补集", complement);
    //差集 数组arr1相对于arr2所没有的
    let diff=arr1.filter(item=>set2.has(item)==false);
    console.log("差集",diff);
</script>
